package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.*;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.potion.Potion;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Skill;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;
import net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.common.BlindnessSkill;
import org.lwjgl.system.CallbackI;

import java.util.Random;

public class DrugSkill extends BaseSkill {

    public DrugSkill(int level){super(level);}

    public DrugSkill(NbtCompound nbtCompound){super(nbtCompound);}

    public DrugSkill(){
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return"每隔一段时间随机向目标脚下生成【缓慢】【中毒】【反胃】【虚弱】【挖掘疲劳】【失明】的药水云";
    }

    public SkillRarity getSkillRarity(){return SkillRarity.Rare;}

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return mobEntity.world.getTime()>getSkilltime();
    }

    @Override
    public boolean onAbilityUse(MobEntity mobEntity) {
        LivingEntity target = mobEntity.getTarget();
        if(canUseAbility(mobEntity) && target != null)
        {
            AreaEffectCloudEntity EffectCloud = EntityType.AREA_EFFECT_CLOUD.create(mobEntity.world);
            EffectCloud.setOwner(mobEntity);
            Random random = new Random();
            int num = random.nextInt(6);
            switch (num)//选择6种负面效果之一
            {
                case 0:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.SLOWNESS,100,getSkillLevel()));
                    break;
                }
                case 1:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.BLINDNESS,100,getSkillLevel()));
                    break;
                }
                case 2:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.NAUSEA,100,getSkillLevel()));
                    break;
                }
                case 3:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.WEAKNESS,100,getSkillLevel()));
                    break;
                }
                case 4:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.POISON,100,getSkillLevel()));
                    break;
                }
                case 5:
                {
                    EffectCloud.addEffect(new StatusEffectInstance(StatusEffects.MINING_FATIGUE,100,getSkillLevel()));
                    break;
                }
            }
            EffectCloud.updatePosition(target.getX(),target.getY(),target.getZ());
            mobEntity.world.spawnEntity(EffectCloud);
            setSkilltime(mobEntity.world.getTime()+getCooldown()-getSkillLevel());
        }
        return true;
    }
}
